package cn.cas.mango.controller;

import cn.cas.mango.dto.Message;
import cn.cas.mango.dto.param.QueryParam;
import cn.cas.mango.service.ConfigService;
import cn.cas.mango.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
@Controller
@RequestMapping("/ReadingAssist/")
@ResponseBody
@CrossOrigin
public class Bi {
  @Autowired
  private SearchService searchService;
  @Autowired
  private ConfigService configService;


  @RequestMapping(value = "bi/searchNews", method = {RequestMethod.GET})
  public Message bi(QueryParam queryParam) throws IOException {
    queryParam.setBiIndex(configService.getPersonIndex());
    return searchService.searchAdvance(queryParam, "bi");
  }

  @RequestMapping(value = "bi/searchNews", method = {RequestMethod.POST})
  public Message biPost( QueryParam queryParam) throws IOException {
    queryParam.setBiIndex(configService.getPersonIndex());
    return searchService.searchAdvance(queryParam, "bi");
  }

  @RequestMapping(value = "bi/searchAdvanced", method = {RequestMethod.GET})
  public Message searchAdvanced(QueryParam queryParam) throws IOException {
    queryParam.setBiIndex(configService.getPersonIndex());
    return searchService.biSearchAdvance(queryParam);
  }

  @RequestMapping(value = "bi/searchAdvanced", method = {RequestMethod.POST})
  public Message searchAdvancedPost2(QueryParam queryParam) throws IOException {
    queryParam.setBiIndex(configService.getPersonIndex());
    return searchService.biSearchAdvance(queryParam);
  }

  @RequestMapping(value = "bi/searchAdvancedTotal", method = {RequestMethod.GET})
  public Message searchAdvancedTotal(QueryParam queryParam) throws IOException {
    queryParam.setBiIndex(configService.getBiPersonTotalIndex());
    return searchService.biSearchAdvance(queryParam);
  }

  @RequestMapping(value = "bi/searchAdvancedTotal", method = {RequestMethod.POST})
  public Message searchAdvancedTotalPost2(QueryParam queryParam) throws IOException {
    queryParam.setBiIndex(configService.getBiPersonTotalIndex());
    return searchService.biSearchAdvance(queryParam);
  }



  @RequestMapping(value = "bi/searchPerson", method = {RequestMethod.GET})
  public Message searchPerson(QueryParam queryParam) throws IOException {
    queryParam.setBiIndex(configService.getPersonIndex());
    return searchService.biSearchPerson(queryParam);
  }

  @RequestMapping(value = "bi/searchPerson", method = {RequestMethod.POST})
  public Message searchPersonPost(QueryParam queryParam) throws IOException {
    queryParam.setBiIndex(configService.getPersonIndex());
    return searchService.biSearchPerson(queryParam);
  }


}
